<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="name" />
    <input type="file" id="img" />
    <hr>
    <button id="submit">追加数据</button>
    <button id="getData">获取数据</button>

</body>
<script>
    // 1-创建FormData实例对象
    const fd = new FormData();
    submit.onclick = function () {
        const name = document.querySelector('#name').value;
        fd.append('name', name);
        // console.log(img.files);
        fd.append('img', img.files[0]);
        console.log(fd);
    }
    getData.onclick = function () {
        const name = fd.get('name');
        const img = fd.get('img');
        console.log(name, img);
    }



    function isRepeat(arr) {
        var hash = {};
        for (var i in arr) {
            if (hash[arr[i]]) {
                return true;
            }
            hash[arr[i]] = true;
        }
        return false;
    }
    console.log(isRepeat([1,2,3,4]));
</script>

</html>